package br.com.onlinebidding.model;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

@Entity
@Table(schema = "db_onlinebidding", name = "Bid")
@NamedQueries({
	@NamedQuery(name = "Bid.findBidByEdict", query = "SELECT b FROM Bid b where b.idEdict= :idEdict"),
	@NamedQuery(name = "Bid.findBidByDateTimeOffer", query = "SELECT b FROM Bid b where b.dateTimeOffer = :dateTimeOffer") })
public class Bid implements Serializable {

	private static final long serialVersionUID = 1L;
	public static final String FIND_BY_EDICT = "Bid.findBidByEdict";
	public static final String FIND_BY_DATETIMEOFFER = "Bid.findBidByDateTimeOffer";
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private int id;	
	
	@JoinColumn(name = "idUser", referencedColumnName = "id")
	@ManyToOne(optional = false)
	private User idUser;	
	
	@JoinColumn(name = "idEdict", referencedColumnName = "id")
	@ManyToOne(optional = false)
	private Edict idEdict;
	
	private Date dateTimeOffer;	
	private double valueUnit;

	public int getId() {return id;}
	public void setId(int id) {this.id = id;}

	public User getIdUser() {return idUser;}
	public void setIdUser(User idUser) {this.idUser = idUser;}

	public Edict getIdEdict() {return idEdict;}
	public void setIdEdict(Edict idEdict) {this.idEdict = idEdict;}

	public Date getDateTimeOffer() {return dateTimeOffer;}
	public void setDateTimeOffer(Date dateTimeOffer) {this.dateTimeOffer = dateTimeOffer;}

	public double getValueUnit() {return valueUnit;}
	public void setValueUnit(double valueUnit) {this.valueUnit = valueUnit;}
	
	@Override
	public int hashCode() {return getId();}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof Bid) {
			 Bid  bid = ( Bid) obj;
			return  bid.getId() == id;}
		return false;
	}
}
